/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.action.adminaction;

import cms.sessionbean.PaymentMgmtRemote;
import cms.util.EjbLocator;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import dto.Payment;
import java.util.Date;
import java.util.List;
import model.ModelConverter;
import model.PaymentModel;

/**
 *
 * @author Timmy
 */
public class PaymentMgmtAction extends ActionSupport{
    
    private String redirectURL; 
    private List<Payment> paymentList; 
    private Payment payment; 
    private List<PaymentModel> paymentModels;
    private  PaymentMgmtRemote cb =(PaymentMgmtRemote) EjbLocator.getInstance().LookUpBeanByName(PaymentMgmtRemote.class,"PaymentMgmt");
    
    private String PayUserName;
    private String PayName;
    private Integer PayType;
    private Integer PayStatus;

    public Integer getPayStatus() {
        return PayStatus;
    }

    public void setPayStatus(Integer PayStatus) {
        this.PayStatus = PayStatus;
    }

 

    public PaymentMgmtRemote getCb() {
        return cb;
    }

    public void setCb(PaymentMgmtRemote cb) {
        this.cb = cb;
    }

    public String getPayUserName() {
        return PayUserName;
    }

    public void setPayUserName(String PayUserName) {
        this.PayUserName = PayUserName;
    }

    public String getPayName() {
        return PayName;
    }

    public void setPayName(String PayName) {
        this.PayName = PayName;
    }

    public Integer getPayType() {
        return PayType;
    }

    public void setPayType(Integer PayType) {
        this.PayType = PayType;
    }
    
    public List<PaymentModel> getPaymentModels() {
        return paymentModels;
    }

    public void setPaymentModels(List<PaymentModel> paymentModels) {
        this.paymentModels = paymentModels;
    }

    public String getRedirectURL() {
        return redirectURL;
    }

    public void setRedirectURL(String redirectURL) {
        this.redirectURL = redirectURL;
    }

    public List<Payment> getPaymentList() {
        return paymentList;
    }

    public void setPaymentList(List<Payment> paymentList) {
        this.paymentList = paymentList;
    }

    public Payment getPayment() {
        return payment;
    }

    public void setPayment(Payment payment) {
        this.payment = payment;
    }
    
    public PaymentMgmtAction() {
    }
    
    public String execute() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public String ShowList()
    {
        this.paymentList = cb.getAllPayments();
        this.paymentModels = ModelConverter.ConvertPaymentList(paymentList);
                
//        ArrayList<PaymentModel> models = new ArrayList<PaymentModel>();
//        for (int i=1; i <= 10; i++)
//        {
//            PaymentModel model = new PaymentModel();
//            model.setAmount(i + "00");
//            model.setApproveDate("2012-12-21");
//            model.setApprover("Timmygod");
//            model.setPayDate("2012-12-20");
//            model.setPayStatus("Approved");
//            model.setPayType("Item");
//            model.setPayName("SB");
//            model.setUserName("NB"+ i);
//            models.add(model);
//        }
//        this.paymentModels = models; 
        return "allList";
    }
    
    public String PendingList()
    {
        return "pending";
    }
    
    public String ChangeStatus()
    {
       Payment pay =  cb.getPayment(PayUserName, PayName, PayType);
       pay.setPayStatus(PayStatus);
       pay.setApproveDate(new Date());
       pay.setApprover(ActionContext.getContext().getSession().get("adminName").toString());
       cb.updatePayment(pay);
        this.redirectURL = "ShowList";
          return "updatesuccess";
    }
}
